﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

public class GamePanel : BasePanel<GamePanel>
{
    public CustomLabel labScore;
    public CustomLabel labTime;
    public CustomTexture texHp;
    public CustomTexture texMap;
    public CustomGUIButton btnSetting;
    public CustomGUIButton btnExit;
    public CustomLabel labNick;

    public float nowHp = 100;
    public int nowScore = 0;
    public float nowTime = 0;

    public int NowScore
    {
        get
        {
            return nowScore;
        }
    }

    public float NowHp
    {
        get
        {
            return nowHp;
        }
    }

    public float NowTime
    {
        get
        {
            return nowTime;
        }
    }

    void Start()
    {
        labScore.SetText("0");
        labTime.SetText("0");
        labNick.SetText(GameDataMgr.Instance.GetNickName());
        btnSetting.clickEvent += () =>
        {
            SettingPanel.Instance.Show();
        };
        btnExit.clickEvent += () =>
        {
            ConfirmPanel.Instance.InitConfirmPanel("退出游戏", "此时退出游戏成绩将丢失", 
            delegate ()
            {
                SceneManager.LoadScene("Start");
            },
            delegate ()
            {
                ConfirmPanel.Instance.Hide();
            });
            ConfirmPanel.Instance.Show();
        };
    }

    public void AddScore(int value)
    {
        nowScore += value;
        labScore.SetText(nowScore.ToString());
    }

    public void UpdataHP(int maxHp, int hp)
    {
        nowHp = hp;
        texHp.Width = ((float)((nowHp/ maxHp) * texHp.Width));
    }

    void Update()
    {
        nowTime += Time.deltaTime;
        labTime.SetText(TimeUtil.Instance.TimeToString(nowTime));
    }
}
